import random
while True:
    # 用户输入彩票号码
    user_input = input("请输入8位数字：")
    # 检查用户输入是否合法
    if len(user_input) != 8 or not user_input.isdigit():
        print("请输入正确的8位数字！")
    else:
        break  # 如果输入正确，则跳出循环
# 初始化中奖情况统计
first_prize_count = 0
second_prize_count = 0
third_prize_count = 0
fourth_prize_count = 0
# 将10000张彩票存储在一个列表中
all_tickets = []
for i in range(1, 10001):
    ticket = []
    for j in range(9):
        # 生成一张随机的彩票
        ticket.append(random.randint(1, 33))
    all_tickets.append(ticket)
# 遍历彩票列表，检查用户输入号码与彩票号码的匹配情况
for i in range(len(all_tickets)):
    count = 0
    for number in user_input:
        if int(number) in all_tickets[i]:
            count += 1
    # 根据中奖情况统计中奖数量
    if count == 8:
        first_prize_count += 1
    elif count == 7:
        second_prize_count += 1
    elif count == 6:
        third_prize_count += 1
    elif count == 5:
        fourth_prize_count += 1
# 输出中奖结果
print("一等奖数量：", first_prize_count)
print("二等奖数量：", second_prize_count)
print("三等奖数量：", third_prize_count)
print("四等奖数量：", fourth_prize_count)
# 计算中奖概率
total_tickets = 10000
first_prize_probability = first_prize_count / total_tickets
second_prize_probability = second_prize_count / total_tickets
third_prize_probability = third_prize_count / total_tickets
fourth_prize_probability = fourth_prize_count / total_tickets
# 输出中奖概率
print("一等奖中奖概率：", first_prize_probability)
print("二等奖中奖概率：", second_prize_probability)
print("三等奖中奖概率：", third_prize_probability)
print("四等奖中奖概率：", fourth_prize_probability)
